/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.test.swat

import com.ages.entity.Actor
import com.ages.graphics.GLDraw
import com.ages.graphics.Sprite
import com.ages.graphics.ViewportSwitcher
import com.ages.math.Vector
import com.ages.math.Vector3D
import javax.media.opengl.GL


object Corpse{
  val fly = new Sprite("/com/ages/test/res/fly3.png",1,1,1)
  val wasp = new Sprite("/com/ages/test/res/wasp3.png",1,1,1)
  val FLY = 0
  val WASP = 1
  
}

class Corpse(v:Vector,corpseType:Int) extends Actor{

  depth = DepthPlaces.BACK
  pos = v

  var time:Double = 0

  def think(){
    time += 1
    if(time>200)
      markForDeletion = true
  }

  def draw(gl:GL)
  {
    val spot = Vector3D(pos.X-40,pos.Y-30,1)
    val box = () =>{
      gl.glEnable(GL.GL_BLEND);
//     Select blending function
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

      val color = (200-time)/200

      gl.glColor4d(color,color,color,if(time<120)1 else 2*(1/(Math.abs(119-time))))
//      gl.glTranslated()
      if(corpseType==Corpse.FLY)
        Corpse.fly.drawWithoutDisplaylist(gl, 0 , 0)
      if(corpseType==Corpse.WASP)
        Corpse.wasp.drawWithoutDisplaylist(gl, 0 , 0)
    }
//    if(time>60)
//      println("1/(Math.abs(59-time))",1/(Math.abs(59-time)))
//    gl.glDisable(GL.GL_LIGHTING)
    ViewportSwitcher.setup2DView(gl)


//    val spot:Vector3D = Vector3D(pos.X,pos.Y,pos.Z-7)

    GLDraw draw box at spot on gl
  }


}
